package com.yupi.springbootinit.service.execution;

import com.yupi.springbootinit.bizmq.BiMessageProducer;
import com.yupi.springbootinit.model.entity.Chart;
import com.yupi.springbootinit.model.vo.BiResponse;
import com.yupi.springbootinit.service.ChartService;
import com.yupi.springbootinit.service.GenChartStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 通过MQ异步消息生成
 * @TODO 反向压力
 */
@Component(value = "gen_mq")
public class GenChartMQ implements GenChartStrategy {

    @Resource
    private BiMessageProducer biMessageProducer;

    @Override
    public BiResponse executeGenChart(Chart chartEntity) {
        long newChartId = chartEntity.getId();
        biMessageProducer.sendMessage(String.valueOf(newChartId));
        BiResponse biResponse = new BiResponse();
        biResponse.setChartId(newChartId);
        return biResponse;
    }
}